import Slider from './slider';
import Star from './star';


class Home {
    constructor(options) {
        this.initEvent();
        this.setTitle();
        this.slider();
        this.star();
        this.shopHover();
    }

    initEvent() {
        console.log('init');
    }

    slider() {
        let slider = new Slider({
            interval: 3000,
            infinite: true,
            content: '.slider'
        });
    }

    star() {
        const s = new Star('.stars', 3);
    }

    setTitle() {
        let titleInit = document.title, isShine = false;

        let shining = setInterval(()=> {
            let title = document.title;
            if (isShine) {
                if (/记/.test(title) == false) {
                    document.title = '记得回来点单哦!'
                } else {
                    document.title = '等着你';
                }
            } else {
                document.title = titleInit;
            }

        }, 500);

        window.onfocus = function () {
            isShine = false;
        };
        window.onblur = function () {
            isShine = true;
        };

        // for IE
        document.onfocusin = function () {
            isShine = false;
        };
        document.onfocusout = function () {
            isShine = true;
        };


    }

    shopHover() {
        let shopCarButton = $('.sidebar-shopcar');
        let shopCar = $('.sidebar');
        let siderHeadButton = $('.sidebar-head a');
        shopCarButton.click(function (e) {
            console.log(e);
            shopCarButton.toggleClass('active');
            shopCar.toggleClass('active');
        });

        siderHeadButton.click(function (e) {
            shopCarButton.toggleClass('active');
            shopCar.toggleClass('active');
        })

    }

}
let home = new Home();